package example.strategy.symmetry;

import com.scop.desensitize.encry.rreversible.symmetry.AbstractSymmetryEncry;
import com.scop.desensitize.exception.strategy.DecodeException;
import com.scop.desensitize.exception.strategy.EncodeException;
import com.scop.desensitize.strategy.rreversible.symmetry.DesStrategy;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Logger;

/**
 * @desc Des策略类的使用示例
 */
public class DesStrategyDemo {

    public static Logger log = Logger.getLogger(DesStrategyDemo.class.getName());

    public static void main(String[] args) throws EncodeException, DecodeException {

        String data = "scop";
        /**
         * @desc  默认密码加密
         */
        defaultEncry(data);

        /**
         * @desc   自定义密码加密
         */
        customEncry(data);
    }

    /**
     * @desc 自定义偏移量，密码
     */
    public static void customEncry(String data) throws EncodeException, DecodeException {
        AbstractSymmetryEncry des = DesStrategy.getInstance();
        des.setIV_PARAMETER("javapdasdlus");
        //密码必须等于8位
        des.setPassword("12534567");

        String encodeStr = (String) des.encode(data);
        String decodeStr = (String) des.decode(encodeStr);

        log.info("自定义密码加密--->默认数据：" + data);
        log.info("自定义密码加密--->加密之后：" + encodeStr);
        log.info("自定义密码加密--->解密之后：" + decodeStr);

    }

    /**
     * @throws NoSuchAlgorithmException
     * @desc 默认执行
     */
    public static void defaultEncry(String data) throws  EncodeException, DecodeException {
        AbstractSymmetryEncry des = DesStrategy.getInstance();
        String encodeStr = (String) des.encode(data);
        String decodeStr = (String) des.decode(encodeStr);

        log.info("默认密码加密--->默认数据：" + data);
        log.info("默认密码加密--->加密数据：" + encodeStr);
        log.info("默认密码加密--->解密数据：" + decodeStr);
    }
}
